package web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import dao.RestaurantDAO;
import dao.UserDAO;

public class SzukajController extends MultiActionController{

	private UserDAO userDAO;

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}
	
	private RestaurantDAO restaurantDAO;
	private LoggedUser loggedUser;
	
	
	
	public void setLoggedUser(LoggedUser loggedUser) {
		this.loggedUser = loggedUser;
	}

	public void setRestaurantDAO(RestaurantDAO restaurantDAO) {
		this.restaurantDAO = restaurantDAO;
	}

	public ModelAndView szukaj(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
			ModelMap modelMap = new ModelMap();
			modelMap.addAttribute("usersList", userDAO.GetAllUsers());
			modelMap.addAttribute("user", loggedUser.getLoggedUser());
			return new ModelAndView("szukaj", modelMap);
			
	}
	
	public ModelAndView searchName(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelMap modelMap = new ModelMap();
		
		String queryString = request.getParameter("searchAdress");
		modelMap.addAttribute("resultList", restaurantDAO.searchName(queryString));
		modelMap.addAttribute("user", loggedUser.getLoggedUser());
		return new ModelAndView("szukaj", modelMap);
	}
}
